/**
 * 
 */
package com.et114.components.simpletable.dao;

import java.util.List;

import com.et114.components.simpletable.DataList;
import com.et114.core.common.AppContext;
import com.et114.core.common.CONST;
import com.et114.core.dao.impl.BaseDAOImpl;
import com.et114.core.dao.vo.BaseVO;
import com.et114.core.utility.BeanUtils;



/*
 * @author guanhw
 */
public class SimpleTableDAOImpl extends BaseDAOImpl implements ISimpleTableDAO {

	
	public DataList queryListDataList ( BaseVO entity  , String method ) throws Exception {
		// TODO Auto-generated method stub
		String pn = BeanUtils.getProperty(  entity  , "pageNum" ) ;  // property
		String ps = BeanUtils.getProperty( entity  , "pageSize" ) ; // property
		int pageNum = Integer.parseInt(  pn  ) ;
		int pageSize = Integer.parseInt(  ps  ) ;
		String cd = AppContext.getFrameWorkPropertiesBean().getDbType() ; 
		if ( CONST.DB_ORACLE.equalsIgnoreCase(  cd ) ) {
			//
			if ( pageNum < 0 ) pageNum = 1 ; 
			if ( pageSize < 0 )  pageSize = 1 ; 
			int firstRow = pageSize * ( pageNum - 1 ) ;
			int lastRow = pageSize * pageNum  + 1 ;
			entity.setFirstRow ( firstRow ) ;
			entity.setLastRow ( lastRow ) ;
		}
		else if ( CONST.DB_SQLSERVER.equalsIgnoreCase(  cd ) ) {
			int ss = entity.getPageSize() * (  ( pageNum > 1 ? pageNum : 1 ) - 1 ) ; 
			entity.setCalculate(  ss  ) ; 
		}
		else if ( CONST.DB_MYSQL.equalsIgnoreCase ( cd ) ) {
			int ss = entity.getPageSize() * (  ( pageNum > 1 ? pageNum : 1 ) - 1 ) ; 
			entity.setCalculate(  ss  ) ; 
		}		
		List list = sqlMapClientTemplate.queryForList( method , entity );
		int total = getCount( entity , "count" + method ).intValue();
		DataList dataList = new DataList( list , total , pageSize , pageNum ); 
		return dataList;			
	}
	
	
}
